<template>
	<div class="classify_con">
		<div class="classify_title" id="meal_title">
			<h1>{{foottimeListTitle}}</h1>
			<p>{{foottimeListDescribe}}</p>
		</div>
		<div id="fnTimeCountDown" class="fnTimeCountDown">
			<!--<span class="year">00</span><font>年</font>
                                <span class="month">00</span><font>月</font>
                                <span class="day">00</span><font>天</font>-->
			<span class="hour">{{int_hour}}</span>
			<font>时</font>
			<span class="mini">{{int_minute}}</span>
			<font>分</font>
			<span class="sec">{{int_second}}</span>
			<font>秒</font>
			<span class="hm">{{int_millisecond}}</span>
		</div>
		<HomemScroll :finalListone="dataSource" :relGroup="relGroup"></HomemScroll>
	</div>
</template>

<script>
	import HomemScroll from "../HomemScroll";
	import { mapGetters, mapMutations } from "vuex";
	import {queryCart, queryGoodsList} from '@/utils/ReturnAxios'
	export default {
		props: {
			foottimeList: {
				type: Array,
				default: () => []
			},
			dataSource: {
				type: Array,
				default: () => []
			},
			relGroup:{
				type:String,
				default:"con004"
			}
		},
		data() {
			return {
				timeObj: {
					mealLabel: '',
					endTime: ''
				},
				int_day: " ",
				int_hour: " ",
				int_minute: " ",
				int_second: " ",
				int_millisecond: "",
				goodsDetailList: []
			}
		},
		computed: {
			...mapGetters('xxy', [
				"getscrollTop",
			]),
			foottimeListTitle() {
				if(this.foottimeList && Array.isArray(this.foottimeList) && this.foottimeList.length > 0) {
					return this.foottimeList[0].relTitle /*this.foottimeList[0].title*/
				}
			},
			foottimeListDescribe() {
				if(this.foottimeList && Array.isArray(this.foottimeList) && this.foottimeList.length > 0) {
					return this.foottimeList[0].relSubtitle /*this.foottimeList[0].describe*/
				}
			},
		},
		components: {
			HomemScroll
		},
		methods: {
			...mapMutations('xxy', [
				"setscrollTop"
			]),
			setmealLabel() {
				this.$emit('transfermealLabel', this.timeObj.mealLabel)
			},
			// 使用timeSlot判断当前属于哪个餐点时间段并获取结束时间
			mealTime() {
				var now = new Date()
				var year = now.getFullYear()
				var month = now.getMonth() + 1
				var day = now.getDate()
				var tomorrow = new Date(parseInt(now.setDate(day + 1)))
				var tomorrowYear = tomorrow.getFullYear()
				var tomorrowMonth = tomorrow.getMonth() + 1
				var tomorrowDay = tomorrow.getDate()
				var hour = now.getHours()
				var minute = now.getMinutes()
				var second = '00'
				var stringTime = year + '/' + month + '/' + day + ' '
				var isTime = hour + ':' + minute;
				if(this.timeSlot('22:30', '24:00', isTime)) {
					this.timeObj.mealLabel = 'breakfast'
					this.timeObj.endTime = tomorrowYear + '/' + tomorrowMonth + '/' + tomorrowDay + ' ' + '8:30:00'
				} else if(this.timeSlot('00:00', '8:29', isTime)) {
					this.timeObj.mealLabel = 'breakfast'
					this.timeObj.endTime = stringTime + '8:29:00'
				} else if(this.timeSlot('8:30', '10:29', isTime)) {
					this.timeObj.mealLabel = 'tea'
					this.timeObj.endTime = stringTime + '10:29:00'
				} else if(this.timeSlot('10:30', '13:59', isTime)) {
					this.timeObj.mealLabel = 'lunch'
					this.timeObj.endTime = stringTime + '13:59:00'
				} else if(this.timeSlot('14:00', '16:29', isTime)) {
					this.timeObj.mealLabel = 'afterNTea'
					this.timeObj.endTime = stringTime + '16:29:00'
				} else if(this.timeSlot('16:30', '19:59', isTime)) {
					this.timeObj.mealLabel = 'dinner'
					this.timeObj.endTime = stringTime + '19:59:00'
				} else if(this.timeSlot('20:00', '22:29', isTime)) {
					this.timeObj.mealLabel = 'supper'
					this.timeObj.endTime = stringTime + '22:29:00'
				}
				return this.timeObj
			},

			timeSlot(beginTime, endTime, varTime) {
				var strb = beginTime.split(":")
				if(strb.length != 2) {
					return false;
				}
				var stre = endTime.split(":");
				if(stre.length != 2) {
					return false;
				}
				var strv = varTime.split(":");
				if(strv.length != 2) {
					return false;
				}
				var b = new Date();
				var e = new Date();
				var v = new Date();
				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);
				v.setHours(strv[0]);
				v.setMinutes(strv[1]);
				if((v.getTime() - b.getTime() >= 0 && (e.getTime() - v.getTime()) > 0)) {
					return true;
				} else {
					return false;
				}
			},

			/*--------------------------------------------------------------------------*/
			fnTimeCountDown() {
				setTimeout(this.show_time, 1000);
			},

			show_time() {
				var time_now, time_end, time_distance, timerID;
				/*var int_day, int_hour, int_minute, int_second;*/
				time_now = new Date();
				time_now = time_now.getTime();
				time_end = new Date(this.timeObj.endTime);
				time_end = time_end.getTime();
				time_distance = time_end - time_now;
				if(time_distance > 0) {
					this.int_day = Math.floor(time_distance / 86400000)
					time_distance -= this.int_day * 86400000;
					this.int_hour = Math.floor(time_distance / 3600000)
					time_distance -= this.int_hour * 3600000;
					this.int_minute = Math.floor(time_distance / 60000)
					time_distance -= this.int_minute * 60000;
					this.int_second = Math.floor(time_distance / 1000)
					time_distance -= this.int_second * 1000;
					this.int_millisecond = Math.floor(time_distance / 100)
					if(this.int_hour < 10)
						this.int_hour = "0" + this.int_hour;
					if(this.int_minute < 10)
						this.int_minute = "0" + this.int_minute;
					if(this.int_second < 10)
						this.int_second = "0" + this.int_second;

					timerID = setTimeout(this.show_time, 1);
				} else {
					clearTimeout(timerID)
				}
			},
			
			/*async queryGoodsDetail(data) {
				var codeList = data.map((item) => {
					return item.goodsCode
				})
				if(codeList.length == 0) {
					return
				}
				//获取编码列表
				var config = {
					goodscodeList: codeList
				}
				//请求详情数据
				var res = await queryGoodsList(config)
				res = res.data
				var detailList = res.data[0]
				this.goodsDetailList = data.map((list) => {
					let detail = detailList.find((item) => {
						return list.goodsCode == item.goodscode
					}) || {}
					detail.image = list.publicityPicture
					return detail
				})
			}*/

		},
		created() {
			this.fnTimeCountDown()
			this.mealTime()
			this.setmealLabel()
		},
		mounted() {
            /*this.queryGoodsDetail(this.dataSource)*/
		},
		/*watch:{
			dataSource(data){
				if(data){
					this.queryGoodsDetail(this.dataSource)
				}
			}
		}*/
	}
</script>

<style>

</style>